package cn.zzf.core;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 工具类
 *
 * @author GaoFeng2017
 * @date 2018-02-12 17:18:13
 **/

public class CrawerUtils {
    public static String getFillZero(int i) {
        if (i <= 1) {
            return "0";
        }
        return "0" + getFillZero(i - 1);
    }
    public static int getNumberLength(Integer number) {
        return number.toString().length();
    }
    public static void saveToProperties(Map<String,String> map, String path) throws IOException {
        Properties teacherInfo = new Properties();
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path  + ".properties"),"utf-8");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String,String> me : entries) {
            teacherInfo.setProperty(me.getKey(),me.getValue());
        }
        teacherInfo.store(out,null);
        out.close();
    }
}
